package com.mask.sca.system.aop;

import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class OperationLogAspect {
    @Pointcut("@annotation(io.swagger.v3.oas.annotations.Operation)")
    public void operationLog() {}

    @AfterReturning(pointcut = "operationLog()", returning = "result")
    public void after(JoinPoint joinPoint, Object result) {
        Operation op = ((org.aspectj.lang.reflect.MethodSignature) joinPoint.getSignature())
                .getMethod().getAnnotation(Operation.class);
        String method = joinPoint.getSignature().toShortString();
        log.info("[操作日志] {} - {}，返回: {}", op.summary(), method, result);
        // 可扩展：记录到数据库、异步处理等
    }
} 